package cn.stylefeng.guns.sys.core.util;

import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
import cn.stylefeng.guns.base.auth.model.LoginUser;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.util.SpringContextHolder;

public class UserKit {

	private static UserService userService;

	public static Long getUserId() {
		if(userService == null) {
			userService = SpringContextHolder.getBean(UserService.class);
		}
		return LoginContextHolder.getContext().getUserId();
	}

	public static User getUser() {
		if(userService == null) {
			userService = SpringContextHolder.getBean(UserService.class);
		}
		Long userId = LoginContextHolder.getContext().getUserId();
		return userService.getById(userId);
	}

	public static LoginUser getLoginUser() {
		if(userService == null) {
			userService = SpringContextHolder.getBean(UserService.class);
		}
		return LoginContextHolder.getContext().getUser();
	}

	public static Long getOrgId() {
		return getUser().getOrgId();
	}

}
